package service.interest;

import vo.InterestVO;
import vo.MajorunitVO;
import vo.MemberVO;
import dao.interest.InterestDAO;

public class InterestServiceImpl implements InterestService{

	private InterestDAO interestDAO;

	public void setInterestDAO(InterestDAO interestDAO) {
		this.interestDAO = interestDAO;
	}

	@Override
	public boolean isInterested(int member_no, int majorunit_no) throws Exception {
		boolean exist=false;
		if(interestDAO.isInterested(new InterestVO(new MemberVO(member_no), new MajorunitVO(majorunit_no)))>0){
			exist=true;
		}
		return exist;
	}

	@Override
	public boolean interestUnit(int member_no, int majorunit_no) throws Exception {
		boolean exist=isInterested(member_no, majorunit_no);
		InterestVO ivo=new InterestVO(new MemberVO(member_no), new MajorunitVO(majorunit_no));
		if(exist){
			interestDAO.uninterestUnit(ivo);
		}else{
			interestDAO.interestUnit(ivo);
		}
		return !exist;
	}

	@Override
	public void uninterestUnit(int member_no, String[] majorunit_no) throws Exception {
		if(majorunit_no!=null){
			for(String no : majorunit_no){
				interestDAO.uninterestUnit(new InterestVO(new MemberVO(member_no), new MajorunitVO(Integer.parseInt(no))));
			}
		}
	}
}
